# 下载器，请求网页，获取html信息
import requests


class HtmlDownloader(object):
    def download(self, url):
        assert url is not None, "doanload()方法参数不能为None"
        # if url is None:
        #     raise Exception("url参数不能为None")
        #     或
        #     return None
        headers = {
            'Host': 'baike.baidu.com',
            'Referer': 'https://baike.baidu.com',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 SE 2.X MetaSr 1.0'
        }

        response = requests.get(url, headers=headers)
        if response.status_code != 200:
            raise Exception(f"请求失败，code: {response.status_code}")

        return response.content.decode(encoding='utf-8')











